package cn.llyong.rpc.client.loadbalance;


import cn.llyong.rpc.common.utils.SpringContextUtil;
import org.springframework.stereotype.Component;

import cn.llyong.rpc.client.enums.LoadBalanceType;
import java.util.List;

/**
 * @description:  负载均衡策略
 * @author: lvyong
 * @date: 2020年07月23日 17:10
 */
@Component
public class LoadBalanceContext {

    public String executeLoadBalance(String type, List<String> serverList){
        LoadBalanceType balanceType = LoadBalanceType.getLoadBalanceEnum(type);
        LoadBalance loadBalance = (LoadBalance) SpringContextUtil.getBean(balanceType.getClazz());
        String host = loadBalance.chose(serverList);
        return host;
    }

}
